package com.ncucoder.iterator;

import java.util.ArrayList;

/**
 * @author <a href="https://edit.ncucoder.com">hsowan</a>
 * @since 2018-12-20 10:35
 */
public class MyArrayList implements Aggregation {

    private ArrayList<Student> list;

    public MyArrayList() {
        list = new ArrayList<>();
        list.add(new Student("Tom", "001", "10000"));
        list.add(new Student("Jack", "002", "10001"));
    }

    @Override
    public Iterator iterator() {
        return new Itr();
    }

    private class Itr implements Iterator {

        private int index = -1;

        @Override
        public boolean hasNext() {
            if (index < list.size() - 1){
                index++;
                return true;
            }else {
                return false;
            }
        }

        @Override
        public Student next() {
            return list.get(index);
        }
    }
}
